<template>
  <BasicModal
    v-bind="$attrs"
    @register="register"
    title="Modal Title"
    @visible-change="handleVisibleChange"
  >
    <div class="pt-3px pr-3px"> 122222222222222222222 </div>
  </BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, nextTick } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';

export default defineComponent({
  components: { BasicModal },
  props: {
    userData: { type: Object },
  },
  setup(props) {
    const modelRef = ref({});

    const [register] = useModalInner((data) => {
      data && onDataReceive(data);
    });

    function onDataReceive(data) {
      console.log('Data Received', data);
      // 方式1;
      // setFieldsValue({
      //   field2: data.data,
      //   field1: data.info,
      // });

      // // 方式2
      modelRef.value = { field2: data.data, field1: data.info };

      // setProps({
      //   model:{ field2: data.data, field1: data.info }
      // })
    }

    function handleVisibleChange(v) {
      v && props.userData && nextTick(() => onDataReceive(props.userData));
    }

    return { register, model: modelRef, handleVisibleChange };
  },
});
</script>
